﻿package app.model.proxy
{	
    import app.facade.App;    
	import app.facade.EApp;
	import app.model.vo.VariableVO;
	import com.adobe.serialization.json.JSON;
	import com.hutra.utils.ArrayUtilities;
	import com.hutra.utils.Syner;
	import flash.events.Event;
	import flash.events.HTTPStatusEvent;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.system.Security;
    import org.puremvc.as3.interfaces.IProxy;
    import org.puremvc.as3.patterns.proxy.Proxy;
	import org.osflash.thunderbolt.Logger;
		
	/**
	 * @author hungconcon
	 */
    public class ConfigProxy extends Proxy implements IProxy
    {
        public static const NAME:String = "ConfigProxy";
		
		 public function ConfigProxy() {
			super(NAME);
        }
		override public function onRegister():void {
			super.onRegister();
		}
		private function securityErrorHandler(event:SecurityErrorEvent):void {
			sendNotification(App.SHOW_ERROR, "ConfigProxy.securityErrorHandler!");
		}
        private function ioErrorHandler(event:IOErrorEvent):void { 
			sendNotification(App.SHOW_ERROR, "ConfigProxy.ioErrorHandler!");
		}		
		public function load():void {
			try {
				var loader:URLLoader = new URLLoader();
					loader.addEventListener(Event.COMPLETE, 					completeHandler);
					loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, 	securityErrorHandler);
					loader.addEventListener(IOErrorEvent.IO_ERROR, 				ioErrorHandler);
					
				var varias:URLVariables = new URLVariables();
					varias.cmd = 'config';
					varias.username = App.USERNAME;
					
				var request:URLRequest = new URLRequest(App.URL["u.0"]);
					request.data = varias;
					loader.load(request);
			}catch (ex:Error) {
				sendNotification(App.SHOW_ERROR, "ConfigProxy.Error.JSON.standardless!");
			}
        }
		
		public var slotlist:Array = new Array();
		public var mail:Number = 0;
		
		private function completeHandler(event:Event):void {
            var loader:URLLoader = URLLoader(event.target);
			try 
			{
				//data = JSON.parse(loader.data);
				//joinData(data.slot, slotlist);
				//parserData(data.free4h);
				//parserCollectGold(data.collect);
				//parserConfigSlot(data.slot_config);
				//
				//mail = Number(data.mail);
			}catch (ex:Error) {
				sendNotification(App.SHOW_ERROR, "ConfigProxy.Error.JSON.standardless!");
			}
			sendNotification(App.LOAD_PROXY_DONE, NAME);
        }
		
    }
}


















